﻿function custom_scroll() {
    if (!$('.ui-accordion-content-active .custom-scroll').hasClass("activated")) {
        $('.ui-accordion-content-active .custom-scroll').ClassyScroll({ sliderSize: '15%', sliderOpacity: 0.3 });
        $('.ui-accordion-content-active .custom-scroll').addClass("activated");
    }
}

$(document).ready(function () {

    $("span.year").text((new Date).getFullYear());

    $('#accordion-west').accordion({
        //event: "click hoverintent"
        autoHide:true,
        activate: function (event, ui) {
	    /*setTimeout(function(){
	    var tree_id = "#bi_apps_tree";
	    var activeLi = $(tree_id).dynatree("getTree").getActiveNode().li;
            var container = $(tree_id + ' .dynatree-container');
                if (activeLi)
                    container.animate({
                        scrollTop: $(activeLi).offset().top - container.offset().top + container.scrollTop()
                    }, 'fast');
	    },3000);*/ //not scrolling
        }
    });
   // custom_scroll();
    $('.scroll-cover').mouseover(function () {
        $(this).find('.scrollbar-path-vertical').css('opacity', '1');
        $(this).find('.scrollbar-path-horizontal').css('opacity', '1');
    });
    $('.scroll-cover').mouseleave(function () {
        $(this).find('.scrollbar-path-vertical').css('opacity', '0');
        $(this).find('.scrollbar-path-horizontal').css('opacity', '0');
    });

    //$(function () {
    //    var div = $('.custom-scroll'),
    //        ul = $('.left-menu ul.dynatree-container');
    //    var divWidth = div.width();
    //    var ulWidth;
    //    div.css({ overflow: 'hidden1' });
    //    div.mousemove(function (e) {
    //        ulWidth = ul.width();
    //        var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
    //        //   div.scrollLeft(left);            
    //        div.animate({ scrollLeft: 'ulWidth' }, 1, 'easeOutQuad');
    //    });
    //});

    $(window).bind('resize', function () {
        var height = $('.accordion').height();
        $('.accordion-content').height(height - 270);
    });




});

$.event.special.hoverintent = {
    setup: function () {
        $(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
    },
    teardown: function () {
        $(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
    },
    handler: function (event) {
        var currentX, currentY, timeout,
            args = arguments,
            target = $(event.target),
            previousX = event.pageX,
            previousY = event.pageY;

        function track(event) {
            currentX = event.pageX;
            currentY = event.pageY;
        };

        function clear() {
            target
                .unbind("mousemove", track)
                .unbind("mouseout", clear);
            clearTimeout(timeout);
        }

        function handler() {
            var prop,
                orig = event;

            if ((Math.abs(previousX - currentX) +
                    Math.abs(previousY - currentY)) < 7) {
                clear();

                event = $.Event("hoverintent");
                for (prop in orig) {
                    if (!(prop in event)) {
                        event[prop] = orig[prop];
                    }
                }
                // Prevent accessing the original event since the new event
                // is fired asynchronously and the old event is no longer
                // usable (#6028)
                delete event.originalEvent;

                target.trigger(event);
            } else {
                previousX = currentX;
                previousY = currentY;
                timeout = setTimeout(handler, 100);
            }
        }

        timeout = setTimeout(handler, 100);
        target.bind({
            mousemove: track,
            mouseout: clear
        });
    }
};



